package com.itheima.config;

import com.itheima.interceptor.DemoInterceptor;
import com.itheima.interceptor.TokenInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

//@Configuration//配置类，不是读取配置文件内容。而是来创建bean对象到spring容器中的
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private DemoInterceptor demoInterceptor;

    @Autowired
    private TokenInterceptor tokenInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //registry注册器，把拦截器添加到拦截器列表里
        registry.addInterceptor(demoInterceptor)
                //配置拦截的路径
                .addPathPatterns("/**");
        /*registry.addInterceptor(tokenInterceptor).addPathPatterns("/**")
        //不拦截的路径
                .excludePathPatterns("/login");*/
    }
}
